package com.stone.design.patterns.observer.weatherdata;

/**
 * @author Stone
 * @version V1.0
 * @description: 显示当前的温度和湿度的显示板
 * @date 4/19/18 21:42
 * @email redsstone@163.com
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement{

    private Subject weatherData;
    private float temperature;
    private float humidity;

    public CurrentConditionsDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temperature = temp;
        this.humidity = humidity;
        display();
    }

    @Override
    public void display() {
        System.out.println("Current conditions:" + temperature + "F degrees and "
                    + humidity + "% humidity");
    }

    /**
     * 注销
     */
    public void unObservie() {
        weatherData.removeObserver(this);
    }
}
